import Types from '../../action/types'
const defaultState = {}

/** 
 * popular:{
 *  java:{
 *      items:[]
 *      isLoading:false
 *  },
 *   ios:{
 *      items:[]
 *      isLoading:false
 *  }
 * 
 * }
 * 
 *@Description: 
 *@param: state
 *@param: action
 *@return: {{}}
 *@Author:  zhengLinPing
**/
export default function onAction(state = defaultState,action){
  
    switch(action.type) {
        case Types.POPULAR_REFRESH_SUCCESS: //下拉刷新成功
            return{
                ...state,
                [action.storeName]:{
                    ...state[action.storeName],
                    items:action.items, 
                    pageData:action.pageData,
                    hideLoadingMore:false,
                    pageIndex:action.pageIndex,
                    isLoading:false
                }
            }
        case Types.POPULAR_REFRESH://下拉刷新
            return{
                ...state,
                [action.storeName]:{
                    ...state[action.storeName],
                    isLoading:false
                }
            }   
        case Types.POPULAR_REFRESH_FAIL: //下拉刷新失败
            return{
                ...state,
                [action.storeName]:{
                    ...state[action.storeName],
                    isLoading:false
                }
            }   
            
        case Types.POPULAR_LOAD_MORE_SUCCESS: //加载更多成功
            return{
                ...state,
                [action.storeName]:{
                    ...state[action.storeName],
                    pageData:action.pageData,
                    pageIndex:action.pageIndex,
                    hideLoadingMore:false
                }
            }    

       case Types.POPULAR_LOAD_MORE_FAIL: //加载更多成功
            return{
                ...state,
                [action.storeName]:{
                    ...state[action.storeName],
                    pageIndex:action.pageIndex,
                    hideLoadingMore:true
                }
            }       
        default:
            return {
                ...state
            }    

    }
}